/*
 * Copyright (c) United Binary LLC.  All rights reserved.
 * 
 * This code is licensed under the MIT License
 * 
 * SEE: http://harnessit.codeplex.com/license
 * 
 */
#region using ...
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
#endregion

namespace UnitedBinary.HarnessIt
{
	#region DetailedErrorTypes Enumeration
	internal enum DetailedErrorTypes 
	{
		Error,
		Warning
	};
	#endregion

	/// <summary>
	/// Summary description for DetailedErrorForm.
	/// </summary>
	internal class DetailedErrorForm : System.Windows.Forms.Form
	{
		#region Member Variables
		private System.Windows.Forms.PictureBox pictureBoxIcon;
		private System.Windows.Forms.ImageList imageListIcons;
		private System.Windows.Forms.TextBox textBoxDetails;
		private System.Windows.Forms.Button buttonOK;
		private System.ComponentModel.IContainer components;
		private DetailedErrorTypes type = DetailedErrorTypes.Error;

		private string errorOverview = "";
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox textBoxOverview;
		private string errorDetails = "";
		#endregion

		#region Static Dialog Display Methods
		internal static void Show(string ErrorOverview, string ErrorDetails)
		{
			if (SystemInformation.UserInteractive)
			{
				DetailedErrorForm frm = new DetailedErrorForm(ErrorOverview, ErrorDetails);
				frm.ShowDialog();
			}
			else
			{
				EmergencyLog.WriteLine(ErrorOverview, ErrorDetails);
			}
		}

		internal static void Show(string ErrorOverview, string ErrorDetails, DetailedErrorTypes type)
		{
			if (SystemInformation.UserInteractive)
			{
				DetailedErrorForm frm = new DetailedErrorForm(ErrorOverview, ErrorDetails, type);
				frm.ShowDialog();
			}
			else
			{
				EmergencyLog.WriteLine(ErrorOverview, ErrorDetails);
			}
		}
		#endregion
		
		#region Construction and Cleanup
		protected DetailedErrorForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// Add any constructor code after InitializeComponent call
			//
			
			// TODO: Get some decent ICONS for this pictureBox.
			//pictureBoxIcon.Image = imageListIcons.Images[0];
			
			SetupForm();
		}
		
		protected DetailedErrorForm(string ErrorOverview, string ErrorDetails)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			this.ErrorDetails = ErrorDetails;
			this.ErrorOverview = ErrorOverview;
			SetupForm();
		}

		protected DetailedErrorForm(DetailedErrorTypes type)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			ErrorType = type;
			SetupForm();
		}

		protected DetailedErrorForm(string ErrorOverview, string ErrorDetails, DetailedErrorTypes type)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			this.ErrorDetails = ErrorDetails;
			this.ErrorOverview = ErrorOverview;
			this.ErrorType = type;

			SetupForm();
		}
		
		private void SetupForm()
		{
			switch(type)
			{
				case DetailedErrorTypes.Error:
					this.Text = "HarnessIt Error";
					break;
				case DetailedErrorTypes.Warning:
					this.Text = "HarnessIt Warning";
					break;
			}

			textBoxOverview.Text = ErrorOverview;
			textBoxDetails.Text = ErrorDetails;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DetailedErrorForm));
			this.pictureBoxIcon = new System.Windows.Forms.PictureBox();
			this.imageListIcons = new System.Windows.Forms.ImageList(this.components);
			this.textBoxDetails = new System.Windows.Forms.TextBox();
			this.buttonOK = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.textBoxOverview = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// pictureBoxIcon
			// 
			this.pictureBoxIcon.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBoxIcon.Image")));
			this.pictureBoxIcon.Location = new System.Drawing.Point(12, 16);
			this.pictureBoxIcon.Name = "pictureBoxIcon";
			this.pictureBoxIcon.Size = new System.Drawing.Size(32, 32);
			this.pictureBoxIcon.TabIndex = 0;
			this.pictureBoxIcon.TabStop = false;
			// 
			// imageListIcons
			// 
			this.imageListIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
			this.imageListIcons.ImageSize = new System.Drawing.Size(32, 32);
			this.imageListIcons.TransparentColor = System.Drawing.SystemColors.Control;
			// 
			// textBoxDetails
			// 
			this.textBoxDetails.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.textBoxDetails.Location = new System.Drawing.Point(56, 116);
			this.textBoxDetails.Multiline = true;
			this.textBoxDetails.Name = "textBoxDetails";
			this.textBoxDetails.ReadOnly = true;
			this.textBoxDetails.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.textBoxDetails.Size = new System.Drawing.Size(540, 164);
			this.textBoxDetails.TabIndex = 2;
			this.textBoxDetails.Text = "";
			// 
			// buttonOK
			// 
			this.buttonOK.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.buttonOK.Location = new System.Drawing.Point(520, 292);
			this.buttonOK.Name = "buttonOK";
			this.buttonOK.TabIndex = 0;
			this.buttonOK.Text = "OK";
			this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(56, 100);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(100, 16);
			this.label1.TabIndex = 4;
			this.label1.Text = "Details:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(56, 16);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(100, 16);
			this.label2.TabIndex = 3;
			this.label2.Text = "Overview:";
			// 
			// textBoxOverview
			// 
			this.textBoxOverview.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.textBoxOverview.Location = new System.Drawing.Point(56, 32);
			this.textBoxOverview.Multiline = true;
			this.textBoxOverview.Name = "textBoxOverview";
			this.textBoxOverview.ReadOnly = true;
			this.textBoxOverview.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.textBoxOverview.Size = new System.Drawing.Size(540, 56);
			this.textBoxOverview.TabIndex = 1;
			this.textBoxOverview.Text = "";
			// 
			// DetailedErrorForm
			// 
			this.AcceptButton = this.buttonOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.buttonOK;
			this.ClientSize = new System.Drawing.Size(608, 326);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.textBoxOverview,
																		  this.label2,
																		  this.label1,
																		  this.buttonOK,
																		  this.textBoxDetails,
																		  this.pictureBoxIcon});
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MinimumSize = new System.Drawing.Size(316, 252);
			this.Name = "DetailedErrorForm";
			this.ShowInTaskbar = false;
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "HarnessIt [Error | Warning]";
			this.ResumeLayout(false);

		}
		#endregion

		#region Windows Form Event Handlers
		private void buttonOK_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		#endregion

		#region Error Properties
		protected string ErrorOverview
		{
			get
			{
				return errorOverview;
			}
			set
			{
				errorOverview = value;
				SetupForm();
			}
		}

		protected string ErrorDetails
		{
			get
			{
				return errorDetails;
			}
			set
			{
				errorDetails = value;
				SetupForm();
			}
		}

		protected DetailedErrorTypes ErrorType
		{
			get
			{
				return type;
			}
			set
			{
				type = value;
				SetupForm();
			}
		}
		#endregion
	}
}
